/*
 * 作者：刘时明
 * 时间：2020/3/5-11:33
 * 作用：
 */
package com.yidu.manage.domain.model;

import com.yidu.manage.domain.SysUser;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

@Data
public class LoginUser implements UserDetails
{
    private Long id;
    private String username;
    private String password;
    private boolean rememberMe;

    /**
     * 权限列表
     */
    private transient Collection<? extends GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities()
    {
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired()
    {
        return false;
    }

    @Override
    public boolean isAccountNonLocked()
    {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired()
    {
        return false;
    }

    @Override
    public boolean isEnabled()
    {
        return false;
    }

    public static LoginUser of(SysUser sysUser)
    {
        if (sysUser == null) return null;
        LoginUser user = new LoginUser();
        // BeanUtils.copyProperties(user, sysUser);
        user.setId(sysUser.getId());
        user.setUsername(sysUser.getUsername());
        return user;
    }

    public void setRoles(Collection<? extends GrantedAuthority> authorities)
    {
        this.authorities = authorities;
    }
}
